﻿// 功能：Native API 调用
// 描述：
// 作者：温伟鹏
// 日期：2010/5/26 15:20:58

using System;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace MeizuSDK.Drawing
{
    /// <summary>
    /// Native API 调用
    /// </summary>
    public class SafeNativeMethods
    {
        // Fields
        public const int BITSPIXEL = 12;
        internal const string Gdi32Dll = "coredll.dll";
        public const int HORZRES = 8;
        internal const string Kernel32Dll = "coredll.dll";
        public const int LOGPIXELSX = 0x58;
        public const int LOGPIXELSY = 90;
        internal const string MsImg32Dll = "coredll.dll";
        internal const string User32Dll = "coredll.dll";
        public const int VERTRES = 10;

        #region 函数
        [DllImport("coredll.dll")]
        public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
        [DllImport("coredll.dll")]
        public static extern void QueryPerformanceCounter(ref long lpPerformanceCount);
        [DllImport("coredll.dll")]
        public static extern void QueryPerformanceFrequency(ref long lpFrequency);
        [DllImport("coredll.dll", SetLastError = true)]
        public static extern int SetBitmapBits(IntPtr hbmp, uint cBytes, byte[] lpBits);

        /// <summary>
        /// 检查指定的指针是否合法
        /// </summary>
        /// <param name="handle"></param>
        internal static void CheckHandle(IntPtr handle)
        {
            if (handle == IntPtr.Zero || handle.ToInt32() == -1)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "非法指针");
            }
        }
        #endregion
    }
}
